/**
 * Copyright (C) 2018-2022
 * All rights reserved, Designed By www.yixiang.co
 * 注意：
 * 本软件为www.yixiang.co开发研制
 */
package co.yixiang.controller.manager.wechat;

import co.yixiang.modules.mp.entity.domain.YxHelp;
import co.yixiang.modules.mp.entity.dto.YxHelpQueryCriteria;
import co.yixiang.modules.mp.service.YxHelpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author hupeng
 * @date 2019-10-07
 */
@Api(tags = "商城:微信图文管理")
@RestController
@RequestMapping("api")
public class WechatHelpController {

    private final YxHelpService helpService;

    public WechatHelpController(YxHelpService helpService) {
        this.helpService = helpService;
    }

    @ApiOperation(value = "查询")
    @GetMapping(value = "/yxHelp")
    public ResponseEntity getYxHelps(YxHelpQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity(helpService.queryAll(criteria, pageable), HttpStatus.OK);
    }


//    @ApiOperation(value = "阅读")
//    @GetMapping(value = "/yxHelp/read")
//    public ResponseEntity readYxHelps(YxHelpQueryCriteria criteria) {
//        return new ResponseEntity(helpService.findById(criteria), HttpStatus.OK);
//    }


    @ApiOperation(value = "新增")
    @PostMapping(value = "/yxHelp")
    @PreAuthorize("hasAnyRole('admin','common','YXHELP_ALL','YXHELP_CREATE')")
    public ResponseEntity create(@Validated @RequestBody YxHelp resources) {
        return new ResponseEntity(helpService.create(resources), HttpStatus.CREATED);
    }


    @ApiOperation(value = "修改")
    @PutMapping(value = "/yxHelp")
    @PreAuthorize("hasAnyRole('admin','common','YXHELP_ALL','YXHELP_EDIT')")
    public ResponseEntity update(@Validated @RequestBody YxHelp resources) {
        helpService.saveOrUpdate(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }


    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/yxHelp/{id}")
    @PreAuthorize("hasAnyRole('admin','common','YXHELP_ALL','YXHELP_DELETE')")
    public ResponseEntity delete(@PathVariable Integer id) {
        helpService.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }


}
